<?php
namespace Api\Event;

/**
 * 战队
 * @author liubo <liubo@ilongyuan.com.cn>
 */
class GameTeamEvent extends BaseEvent
{

    public function info($id, $showMember = false)
    {
        $teaminfo = service('GameTeam')->find($id);
        if (!$teaminfo || $teaminfo['status'] != 1) {
            return false;
        }
        uri_format($teaminfo['logo']);
        $showMember && $teaminfo['members'] = $this->members($id);
        return $teaminfo;
    }

    public function members($id)
    {
        $members = service('GameTeamMember')->where(['team_id' => $id, 'status' => 1])->order('sort asc')->select();
        if (!$members) {
            return [];
        }
        $list = [];
        foreach ($members as $value) {
            uri_format($value['avatar']);
            $list[] = $value;
        }
        return $list;
    }

    public function lists($query = [], $p = 1, $limit = 10)
    {
        $map['status'] = 1;
        $query && $map = array_merge($map, $query);
        $teams = service('GameTeam')->where($map)->field('id,name,logo,game_id')->select();
        foreach ($teams as &$value) {
            uri_format($value['logo']);
        }
        return $teams ? array_values($teams) : [];
    }
}